package com.tech.tool.service.impl;

import com.tech.tool.constant.PageConstant;
import com.tech.tool.dataobject.UserInfo;
import com.tech.tool.enums.DeleteEnum;
import com.tech.tool.repository.UserInfoRepository;
import com.tech.tool.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoRepository repository;

    @Override
    public UserInfo findByUserLogin(String loginName) {
        return repository.findByUserLogin(loginName);
    }

    @Override
    public Page<UserInfo> findByUserName(String userName) {
        PageRequest pageRequest = PageRequest.of(PageConstant.PAGE_INDEX, PageConstant.PAGE_LIMIT);
        return repository.findByUserDeleteAndUserName(DeleteEnum.EXIST.getCode(), '%' + userName + '%', pageRequest);
    }

    @Override
    public UserInfo save(UserInfo userInfo) {
        return repository.save(userInfo);
    }
}
